package cn.zzszxyy.hr.comm;

import cn.zzszxyy.hr.model.MenuEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者:张伟
 * <p>
 * 联系:adamzzww@163.com
 * 时间:2016-11-30
 * 说明:无
 */
public class ConvertToTree {


    /**
     * 获取菜单树形列表（含URL）
     *
     * @param MenuTreeList 菜单分类list
     * @param checkedId    默认选中值
     * @param url          点击的url模版
     * @return
     */
    public static List<ZTree> getMenuUrlTree(List<MenuEntity> MenuTreeList, String checkedId, String url) {
        List<ZTree> list = new ArrayList<ZTree>();
        for (MenuEntity sb : MenuTreeList) {
            ZTree tree = new ZTree();
            tree.setId(sb.getMenuId().toString());
            tree.setpId(sb.getpMenuId().toString());
            tree.setUrl(url + "/" + sb.getMenuId().toString());
            tree.setName(sb.getMenuName());
            tree.setOpen(true);
            tree.setTarget("_self");
            if (!StringUtil.isEmpty(checkedId)) {
                if (checkedId.equals(sb.getMenuId().toString())) {
                    tree.setChecked(true);
                }
            } else {
                tree.setChecked(false);
            }
            list.add(tree);
        }
        return list;
    }

    /**
     * 获取菜单树形列表（不含URL）
     *
     * @param MenuTreeList
     * @param checkedList
     * @return
     */
    public static List<ZTree> getMenuTree(List<MenuEntity> MenuTreeList, List<String> checkedList) {
        List<ZTree> list = new ArrayList<ZTree>();
        for (MenuEntity sb : MenuTreeList) {
            ZTree tree = new ZTree();
            tree.setId(sb.getMenuId().toString());
            tree.setpId(sb.getpMenuId().toString());
            tree.setName(sb.getMenuName());
            tree.setOpen(true);
            tree.setTarget("_self");
            if (checkedList.size() > 0) {
                if (checkedList.contains(sb.getMenuId().toString())) {
                    tree.setChecked(true);
                }
            } else {
                tree.setChecked(false);
            }
            list.add(tree);
        }
        return list;
    }

}
